Page({
  data: {
    downloadList: [
      {
        id: 1,
        title: "产品创新的洞察力：音频课",
        videoUrl: "https://example.com/videos/1.mp4",
        coverUrl: "/images/course1.jpg",
        duration: "12:34",
        progress: 0,
        downloading: false
      },
      // 其他视频项...
    ]
  },

  // 处理下载视频
  handleDownload(e) {
    const itemId = e.currentTarget.dataset.id;
    const itemIndex = this.data.downloadList.findIndex(item => item.id === itemId);
    const videoUrl = this.data.downloadList[itemIndex].videoUrl;
    
    // 更新状态为下载中
    this.setData({
      [`downloadList[${itemIndex}].downloading`]: true
    });
    
    // 开始下载
    const downloadTask = wx.downloadFile({
      url: videoUrl,
      success: (res) => {
        if (res.statusCode === 200) {
          // 保存到本地
          wx.saveFile({
            tempFilePath: res.tempFilePath,
            success: (saveRes) => {
              this.setData({
                [`downloadList[${itemIndex}].downloading`]: false,
                [`downloadList[${itemIndex}].savedPath`]: saveRes.savedFilePath
              });
              wx.showToast({
                title: '下载完成',
                icon: 'success'
              });
            }
          });
        }
      },
      fail: (err) => {
        console.error('下载失败:', err);
        wx.showToast({
          title: '下载失败',
          icon: 'none'
        });
        this.setData({
          [`downloadList[${itemIndex}].downloading`]: false
        });
      }
    });
    
    // 监听下载进度
    downloadTask.onProgressUpdate((res) => {
      this.setData({
        [`downloadList[${itemIndex}].progress`]: res.progress
      });
    });
  }
});